// Finder.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include  <TCHAR.h>
#include <iostream>


using namespace std;

// void FindDir(TCHAR* parent)
// {
// 	HANDLE hFile = NULL;
// 	WIN32_FIND_DATA fd = {0};
// 	TCHAR tmp[MAX_PATH] = {0};
// 	TCHAR sub[MAX_PATH] = {0};
// 	swprintf(tmp, _T("%s\\*.*"), parent);
// 
// 	hFile = FindFirstFile(tmp, &fd);
// 	if(hFile != INVALID_HANDLE_VALUE)
// 	{
// 		do 
// 		{
// 			if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
// 			{
// 				if(*fd.cFileName == '.')
// 					continue;
// 				printf("%s\\%s\n", parent, fd.cFileName);
// 				swprintf(sub, _T("%s\\%s"), parent, fd.cFileName);
// 				FindDir(sub);
// 			}
// 		}while(FindNextFile(hFile, &fd));
// 		FindClose(hFile);
// 		hFile = NULL;
// 	}
// }

BOOL  DirectoryList(TCHAR* Path)
{
	WIN32_FIND_DATA FindData;
	HANDLE hError;
	int FileCount = 0;
	TCHAR FilePathName[MAX_PATH] = {0};

	TCHAR FullPathName[MAX_PATH] = {0};
	wcscpy(FilePathName, Path);
	wcscat(FilePathName, _T("\\*.*"));

	hError = FindFirstFile(FilePathName, &FindData);
	if (hError == INVALID_HANDLE_VALUE)
	{
		cout << _T("failed.") << endl;
		return 0;
	}
	while(::FindNextFile(hError, &FindData))
	{
		if (wcscmp(FindData.cFileName, _T(".")) == 0 
			|| wcscmp(FindData.cFileName, _T("..")) == 0 )
		{
			continue;
		}

		wsprintf(FullPathName, _T("%s\\%s"), Path, FindData.cFileName);
		FileCount++;

		// cout << FileCount << _T(" : ") << FullPathName << endl;
		printf ("\n %d %s", FileCount, FullPathName);
        DeleteFile(FullPathName);
		if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		{
			printf ("<Dir>");
			DirectoryList(FullPathName);
		}
	}
	return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
	DirectoryList(_T("F:\\winxtest"));
	cin.get();
	return 0;
}

